import java.io.*;
import java.util.StringTokenizer;

public class 宝物筛选 {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int MAXN = 1001;
    public static int MAXW = 40001;
    public static int[] val = new int[MAXN];
    public static int[] weight = new int[MAXN];
    public static int[] dp = new int[MAXW];
    public static int n,w,cnt;
    public static void main(String[] args) throws IOException {
        n = in.nextInt();
        w = in.nextInt();
        cnt = 0;
        // 完成二进制初始化
        for (int i = 1; i <= n; i++) {
            int a = in.nextInt(); // 价值
            int b = in.nextInt(); // 重量
            int c = in.nextInt(); // 数量
            for (int j = 1; j <= c; j *= 2) {
                val[++cnt] = j * a;
                weight[cnt] = j * b;
                c -= j;
            }
            if (c > 0) {
                val[++cnt] = c * a;
                weight[cnt] = c * b;
            }
        }
        out.println(compute());
        out.close();
    }

    private static int compute() {
        for (int i = 1; i <= cnt; i++) {
            for (int j = w; j >= weight[i]; j--) {
                dp[j] = Math.max(dp[j],dp[j - weight[i]] + val[i]);
            }
        }
        return dp[w];
    }


    public static class Read // 自定义快速读入
    {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException
        {
            while(!st.hasMoreTokens())
            {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        String nextLine() throws IOException
        {
            return bf.readLine();
        }

        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
}
